﻿using System;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using System.Windows.Data;
using EIA.SLClient.ProjectManage.Infrastructure;

namespace EIA.SLClient.ProjectManage
{
    public class ListsResource : SimpleMvvmToolkit.ViewModelBase<ListsResource>
    {
        public static ListsResource Instance { get; private set; }

        public ListsResource()
        {
            if (IsInDesignMode) return;
            Instance = this;
            RegisterToReceiveMessages<EIA.Basic.Model.TStaff>(EIA.SLClient.ProjectManage.Infrastructure.MessageTokens.LOGIN_STAFF_IDENTIFIED, EP_StaffIdentified);
        }

        private void EP_StaffIdentified(object sender, SimpleMvvmToolkit.NotificationEventArgs<EIA.Basic.Model.TStaff> e)
        {
            LoadDicTypeCollection();
            LoadOrganizationCollection();
            LoadEngineerCollection();
            LoadStaffCollection();
            LoadApproverCollection();
        }

        public void LoadOrganizationCollection()
        {
            EIA.PM.BLL.ClientProxy.TOrganizationProxy proxy = new PM.BLL.ClientProxy.TOrganizationProxy();
            proxy.ListAll((lst) =>
            {
                OrganizationCollection = new ObservableCollection<EIA.PM.Model.TOrganization>(lst);
            }, (ex) =>
            {

            });
        }

        public void LoadEngineerCollection()
        {
            EIA.PM.BLL.ClientProxy.TEngineerProxy proxy = new PM.BLL.ClientProxy.TEngineerProxy();
            proxy.ListAll((lst) =>
            {
                EngineerCollection = new ObservableCollection<EIA.PM.Model.TEngineer>(lst);
            }, (ex) =>
            {

            });
        }

        public void LoadApproverCollection()
        {
            EIA.PM.BLL.ClientProxy.TApproverProxy proxy = new PM.BLL.ClientProxy.TApproverProxy();
            proxy.ListAll((lst) =>
            {
                ApproverCollection = new ObservableCollection<EIA.PM.Model.TApprover>(lst);
            }, (ex) =>
            {

            });
        }

        public void LoadStaffCollection()
        {
            EIA.Basic.BLL.ClientProxy.TStaffProxy proxy = new EIA.Basic.BLL.ClientProxy.TStaffProxy();
            proxy.ListAll((lst) =>
            {
                StaffCollection = new ObservableCollection<EIA.Basic.Model.TStaff>(lst);
            }, (ex) =>
            {

            });
        }

        #region 字典

        private void LoadDicTypeCollection()
        {
            EIA.Basic.BLL.ClientProxy.DicItemProxy proxy = new EIA.Basic.BLL.ClientProxy.DicItemProxy();
            proxy.ListAll((lst) =>
            {
                AllDicItemCollection = new ObservableCollection<Basic.Model.DicItem>(lst);

                var l = from EIA.Basic.Model.DicItem di in lst where di.DicTid == DicTypes.HYLX select di;
                if(l!=null) HYLXCollection = new ObservableCollection<EIA.Basic.Model.DicItem>(l);

                l = from EIA.Basic.Model.DicItem di in lst where di.DicTid == DicTypes.XMLX select di;
                if (l != null) XMLXCollection = new ObservableCollection<EIA.Basic.Model.DicItem>(l);

                l = from EIA.Basic.Model.DicItem di in lst where di.DicTid == DicTypes.XMSZD select di;
                if (l != null) XMSZDCollection = new ObservableCollection<EIA.Basic.Model.DicItem>(l);

                l = from EIA.Basic.Model.DicItem di in lst where di.DicTid == DicTypes.XMSPBM select di;
                if (l != null) XMSPBMCollection = new ObservableCollection<EIA.Basic.Model.DicItem>(l);

                l = from EIA.Basic.Model.DicItem di in lst where di.DicTid == DicTypes.XMLY select di;
                if (l != null) XMLYCollection = new ObservableCollection<EIA.Basic.Model.DicItem>(l);

                l = from EIA.Basic.Model.DicItem di in lst where di.DicTid == DicTypes.XMJD select di;
                if (l != null) XMJDCollection = new ObservableCollection<EIA.Basic.Model.DicItem>(l);

                l = from EIA.Basic.Model.DicItem di in lst where di.DicTid == DicTypes.DKFS select di;
                if (l != null) DKFSCollection = new ObservableCollection<EIA.Basic.Model.DicItem>(l);

                l = from EIA.Basic.Model.DicItem di in lst where di.DicTid == DicTypes.HTQDZT select di;
                if (l != null) HTQDZTCollection = new ObservableCollection<EIA.Basic.Model.DicItem>(l);

                l = from EIA.Basic.Model.DicItem di in lst where di.DicTid == DicTypes.HTZT select di;
                if (l != null) HTZTCollection = new ObservableCollection<EIA.Basic.Model.DicItem>(l);

                l = from EIA.Basic.Model.DicItem di in lst where di.DicTid == DicTypes.KPZT select di;
                if (l != null) KPZTCollection = new ObservableCollection<EIA.Basic.Model.DicItem>(l);

                l = from EIA.Basic.Model.DicItem di in lst where di.DicTid == DicTypes.DKZT select di;
                if (l != null) DKZTCollection = new ObservableCollection<EIA.Basic.Model.DicItem>(l);

                l = from EIA.Basic.Model.DicItem di in lst where di.DicTid == DicTypes.GDZT select di;
                if (l != null) GDZTCollection = new ObservableCollection<EIA.Basic.Model.DicItem>(l);

                l = from EIA.Basic.Model.DicItem di in lst where di.DicTid == DicTypes.BGYP select di;
                if (l != null) BGYPCollection = new ObservableCollection<EIA.Basic.Model.DicItem>(l);

                l = from EIA.Basic.Model.DicItem di in lst where di.DicTid == DicTypes.XMYQSPZT select di;
                if (l != null) XMYQSPZTCollection = new ObservableCollection<EIA.Basic.Model.DicItem>(l);

                l = from EIA.Basic.Model.DicItem di in lst where di.DicTid == DicTypes.TJXS select di;
                if (l != null) TJXSCollection = new ObservableCollection<EIA.Basic.Model.DicItem>(l);

            });
        }

        protected ObservableCollection<EIA.Basic.Model.DicItem> _AllDicItemCollection;
        /// <summary>
        /// 所有字典项
        /// </summary>
        public ObservableCollection<EIA.Basic.Model.DicItem> AllDicItemCollection
        {
            get { return _AllDicItemCollection; }
            set
            {
                _AllDicItemCollection = value;
                NotifyPropertyChanged(m => m.AllDicItemCollection);
            }
        }

        protected ObservableCollection<EIA.Basic.Model.DicItem> _HYLXCollection;
        /// <summary>
        /// 行业类型
        /// </summary>
        public ObservableCollection<EIA.Basic.Model.DicItem> HYLXCollection
        {
            get { return _HYLXCollection; }
            set
            {
                _HYLXCollection = value;
                NotifyPropertyChanged(m => m.HYLXCollection);
            }
        }

        protected ObservableCollection<EIA.Basic.Model.DicItem> _XMLXCollection;
        /// <summary>
        /// 项目类型
        /// </summary>
        public ObservableCollection<EIA.Basic.Model.DicItem> XMLXCollection
        {
            get { return _XMLXCollection; }
            set
            {
                _XMLXCollection = value;
                NotifyPropertyChanged(m => m.XMLXCollection);
            }
        }

        protected ObservableCollection<EIA.Basic.Model.DicItem> _XMSZDCollection;
        /// <summary>
        /// 项目所在地
        /// </summary>
        public ObservableCollection<EIA.Basic.Model.DicItem> XMSZDCollection
        {
            get { return _XMSZDCollection; }
            set
            {
                _XMSZDCollection = value;
                NotifyPropertyChanged(m => m.XMSZDCollection);
            }
        }

        protected ObservableCollection<EIA.Basic.Model.DicItem> _XMSPBMCollection;
        /// <summary>
        /// 项目审批部门
        /// </summary>
        public ObservableCollection<EIA.Basic.Model.DicItem> XMSPBMCollection
        {
            get { return _XMSPBMCollection; }
            set
            {
                _XMSPBMCollection = value;
                NotifyPropertyChanged(m => m.XMSPBMCollection);
            }
        }

        protected ObservableCollection<EIA.Basic.Model.DicItem> _XMLYCollection;
        /// <summary>
        /// 项目来源
        /// </summary>
        public ObservableCollection<EIA.Basic.Model.DicItem> XMLYCollection
        {
            get { return _XMLYCollection; }
            set
            {
                _XMLYCollection = value;
                NotifyPropertyChanged(m => m.XMLYCollection);
            }
        }

        protected ObservableCollection<EIA.Basic.Model.DicItem> _XMJDCollection;
        /// <summary>
        /// 项目进度
        /// </summary>
        public ObservableCollection<EIA.Basic.Model.DicItem> XMJDCollection
        {
            get { return _XMJDCollection; }
            set
            {
                _XMJDCollection = value;
                NotifyPropertyChanged(m => m.XMJDCollection);
            }
        }

        protected ObservableCollection<EIA.Basic.Model.DicItem> _DKFSCollection;
        /// <summary>
        /// 到款方式
        /// </summary>
        public ObservableCollection<EIA.Basic.Model.DicItem> DKFSCollection
        {
            get { return _DKFSCollection; }
            set
            {
                _DKFSCollection = value;
                NotifyPropertyChanged(m => m.DKFSCollection);
            }
        }

        protected ObservableCollection<EIA.Basic.Model.DicItem> _HTQDZTCollection;
        /// <summary>
        /// 合同签订主体
        /// </summary>
        public ObservableCollection<EIA.Basic.Model.DicItem> HTQDZTCollection
        {
            get { return _HTQDZTCollection; }
            set
            {
                _HTQDZTCollection = value;
                NotifyPropertyChanged(m => m.HTQDZTCollection);
            }
        }

        protected ObservableCollection<EIA.Basic.Model.DicItem> _HTZTCollection;
        /// <summary>
        /// 合同状态
        /// </summary>
        public ObservableCollection<EIA.Basic.Model.DicItem> HTZTCollection
        {
            get { return _HTZTCollection; }
            set
            {
                _HTZTCollection = value;
                NotifyPropertyChanged(m => m.HTZTCollection);
            }
        }

        protected ObservableCollection<EIA.Basic.Model.DicItem> _KPZTCollection;
        /// <summary>
        /// 开票状态
        /// </summary>
        public ObservableCollection<EIA.Basic.Model.DicItem> KPZTCollection
        {
            get { return _KPZTCollection; }
            set
            {
                _KPZTCollection = value;
                NotifyPropertyChanged(m => m.KPZTCollection);
            }
        }

        protected ObservableCollection<EIA.Basic.Model.DicItem> _DKZTCollection;
        /// <summary>
        /// 到款状态
        /// </summary>
        public ObservableCollection<EIA.Basic.Model.DicItem> DKZTCollection
        {
            get { return _DKZTCollection; }
            set
            {
                _DKZTCollection = value;
                NotifyPropertyChanged(m => m.DKZTCollection);
            }
        }

        protected ObservableCollection<EIA.Basic.Model.DicItem> _GDZTCollection;
        /// <summary>
        /// 归档状态
        /// </summary>
        public ObservableCollection<EIA.Basic.Model.DicItem> GDZTCollection
        {
            get { return _GDZTCollection; }
            set
            {
                _GDZTCollection = value;
                NotifyPropertyChanged(m => m.GDZTCollection);
            }
        }

        protected ObservableCollection<EIA.Basic.Model.DicItem> _BGYPCollection;
        /// <summary>
        /// 办公用品
        /// </summary>
        public ObservableCollection<EIA.Basic.Model.DicItem> BGYPCollection
        {
            get { return _BGYPCollection; }
            set
            {
                _BGYPCollection = value;
                NotifyPropertyChanged(m => m.BGYPCollection);
            }
        }

        protected ObservableCollection<EIA.Basic.Model.DicItem> _XMYQSPZTCollection;
        /// <summary>
        /// 项目延期审批状态
        /// </summary>
        public ObservableCollection<EIA.Basic.Model.DicItem> XMYQSPZTCollection
        {
            get { return _XMYQSPZTCollection; }
            set
            {
                _XMYQSPZTCollection = value;
                NotifyPropertyChanged(m => m.XMYQSPZTCollection);
            }
        }

        protected ObservableCollection<EIA.Basic.Model.DicItem> _TJXSCollection;
        /// <summary>
        /// 提奖系数
        /// </summary>
        public ObservableCollection<EIA.Basic.Model.DicItem> TJXSCollection
        {
            get { return _TJXSCollection; }
            set
            {
                _TJXSCollection = value;
                NotifyPropertyChanged(m => m.TJXSCollection);
            }
        }

        #endregion


        protected ObservableCollection<EIA.Basic.Model.TStaff> _StaffCollection;
        /// <summary>
        /// 员工
        /// </summary>
        public ObservableCollection<EIA.Basic.Model.TStaff> StaffCollection
        {
            get { return _StaffCollection; }
            set
            {
                _StaffCollection = value;
                NotifyPropertyChanged(m => m.StaffCollection);
            }
        }

        protected ObservableCollection<EIA.PM.Model.TOrganization> _OrganizationCollection;
        /// <summary>
        /// 建设单位
        /// </summary>
        public ObservableCollection<EIA.PM.Model.TOrganization> OrganizationCollection
        {
            get { return _OrganizationCollection; }
            set
            {
                _OrganizationCollection = value;
                NotifyPropertyChanged(m => m.OrganizationCollection);
            }
        }

        protected ObservableCollection<EIA.PM.Model.TEngineer> _EngineerCollection;
        /// <summary>
        /// 工程师
        /// </summary>
        public ObservableCollection<EIA.PM.Model.TEngineer> EngineerCollection
        {
            get { return _EngineerCollection; }
            set
            {
                _EngineerCollection = value;
                NotifyPropertyChanged(m => m.EngineerCollection);
            }
        }

        protected ObservableCollection<EIA.PM.Model.TApprover> _ApproverCollection;
        /// <summary>
        /// 审批人员
        /// </summary>
        public ObservableCollection<EIA.PM.Model.TApprover> ApproverCollection
        {
            get { return _ApproverCollection; }
            set
            {
                _ApproverCollection = value;
                NotifyPropertyChanged(m => m.ApproverCollection);
            }
        }

    }
}
